<!--
 * @Author: delin66
 * @Date: 2025-02-28 20:38:56
 * @LastEditors: delin66
 * @LastEditTime: 2025-05-26 09:43:33
 * @Descripttion: 
-->
<template>
  <div class="container">
    <div class="content">
      <div class="box">
        <div class="sub_title">政策文件</div>
        <div class="file">
          
          <el-table border :data="files" stripe style="width: 100%">
            <el-table-column align="center" label="文件名">
              <template #default="{ row }">
                <div @click="download(row.filepath)" class="c-p filename">
                  {{ formatFileName(row.filename) }}
                </div>
              </template>
            </el-table-column>
            <el-table-column align="center" width="150px" label="发布时间">
              <template #default="{ row }">
                <div>{{ row.createTime?.split(' ')[0] ?? '-' }}</div>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
<!--      <div class="divide"></div>-->
<!--      <div class="box">-->
<!--        <div class="sub_title">信息审核结果公告</div>-->
<!--        <div class="file">-->

<!--        </div>-->
<!--      </div>-->
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { ElTable, ElTableColumn } from 'element-plus';
import { useDownload } from '@/hooks/useDownload';
import { getFileList } from '@/api/file';
import back from '@/components/back/index.vue';
import { Search } from '@element-plus/icons-vue';

const router = useRouter();

// 跳转详情
function toDynamicDetail(id: string | number) {
  const { href } = router.resolve({
    name: 'noticeDetail',
    query: {
      id,
    },
  });
  window.open(href, '_blank');
}

// 下载文件的方法，传个url即可
const { download } = useDownload();

interface File {
  filename: string;
  filepath: string;
  createTime: string;
}

// 查询某个文件
const fileName = ref('');
function onDoSearch() {
  localGetFileList();
}

const files = ref<File[]>([]);
const total = ref<number>(0);
onMounted(() => {
  localGetFileList();
});
function localGetFileList() {
  getFileList({
    current: current.value,
    size: 8,
    fileName: fileName.value ? fileName.value : null,
  }).then((res: any) => {
    if (res.code === 200) {
      files.value = res.data?.records;
      total.value = res.data?.total;
    }
  });
}
// 分页
const current = ref<number>(1);

function formatFileName(filename: string) {
  const extension = filename.substring(filename.lastIndexOf('.') + 1);
  const originName = filename.substring(0, filename.lastIndexOf('_'));
  return `${originName}.${extension}`;
}
</script>

<style scoped lang="scss">
.container {
  margin-top: 30px;
  display: flex;
  flex-direction: column;
  width: 100%;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  .header {
    display: flex;
    height: 50px;
    line-height: 50px;
    text-align: center;
    font-size: 25px;
    font-weight: bold;
    color: white;
    background-color: #0370c2;
    clip-path: polygon(0 0, 100% 0, 100% 85%, 96% 85%, 96% 100%, 4% 100%, 4% 85%, 0 85%);
    .title {
      margin: 0 auto;
      font-weight: bolder;
    }
    .more {
      margin-right: 40px;
      font-weight: bold;
      font-size: 16px;
      cursor: pointer;
      z-index: 99;
    }
  }

  .content {
    height: 450px;
    display: flex;
    justify-content: space-between;
    .box {
      width: 100%;
      .sub_title {
        width: 60%;
        margin: auto;
        margin-top: -10px;
        text-align: center;
        line-height: 40px;
        font-size: 20px;
        font-weight: bold;
        color: white;
        background-color: #0370c2;
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
      }
    }
    .divide {
      margin: auto 0;
      height: 80%;
      width: 1px;
      background-color: rgba(0, 0, 0, 0.1);
    }
  }
}
.notice-list {
  padding: 0 30px;
  flex: 1;
  width: 100%;
  padding-top: 30px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  li {
    position: relative;
    padding: 0 5%;
    margin-bottom: 5px;
    display: flex;
    justify-content: space-between;
    &::before {
      content: '';
      position: absolute;
      width: 5px;
      height: 5px;
      background-color: #338ccb;
      top: 50%;
      left: 2.5%;
      transform: translate(-50%, -50%);
    }
    .title {
      margin-left: 10px;
      max-width: 85%;
      font-size: 16px;
      &:hover {
        cursor: pointer;
        color: #338ccb;
      }
    }
    .create-time {
      text-wrap: nowrap;
    }
  }
}
.file {
    margin: 0 20px;
    .search {
        width: 90%;
        display: flex;
        justify-content: space-between;
        margin: 10px auto;
    }
}

.file .filename:hover {
  text-decoration: none;
  color: #409eff;
}
</style>
